<template>
	<form class="flex-col page">
		<view class="flex-col flex-auto group">
			<view class="flex-row items-center section space-x-8">
				<view class="flex-row items-center group_2">
					<image class="image_5" src="../../static/images/407378d01e90922d2cefe7d724f87c62.png" />
					<text class="font_2 text_5">+86</text>
				</view>
				<input class="font_3" name="phone" v-model="phone" maxlength="11" placeholder="请输入手机号码" />
			</view>
			<view class="flex-row justify-between group_3">
				<!-- <view class="flex-col justify-start items-start text-wrapper"> -->
				<input class="font_3 text_6" name="code" v-model="code" maxlength="6" placeholder="请输入验证码" />
				<text type="default" class="font_3 text_7" v-bind:disabled="btndisabled"
					@click="sendCode()">{{codeMsg}}</text>
				<!-- </view> -->
			</view>

			<view class="flex-row items-center group_4 space-x-8">
				<!-- <view class="section_2" :class="{ checked: checkeAccept }" @click="checkeAccept = !checkeAccept"></view> -->
				<!-- <text class="text_8">已阅读并同意账号</text> -->
				<!-- <text class="text_9" @click="showArctile">《用户协议》和《隐私政策》</text> -->
			</view>
			<view class="uni-btn-v">
				<button formType="submit" class="font_2 text_9" @click="register()">下一步</button>
			</view>
			<!-- <text class="self-center text_10">收不到验证码？</text> -->
		</view>
	</form>
</template>

<script>
	import {
		_paschangecode
	} from '@/service/user.js'
	import {
		_isok
	} from '@/service/user.js'
	_isok
	export default {
		components: {},
		data() {
			return {
				phone: '',
				code: '',
				checkeAccept: false,
				t: 60,
				codeMsg: '获取验证码',
				btndisabled: false,
				judgecode: ''
			};
		},
		methods: {
			//传手机号码
			// uni.setStorageSync('phone', this.phone)
			//确认是否授权
			judgeAgree() {
				if (!this.checkeAccept) {
					this.$api.msg('请先确认授权');
					return false;
				}
				return true;
			},
			// 验证手机号码
			validPhone(phone) {
				let valid = false;
				let rule = /^1[3456789]\d{9}$/;
				if (phone === '') {
					this.$api.msg('手机号码不能为空');
				} else if (!rule.test(this.phone)) {
					this.$api.msg('请输入正确的手机号码');
				} else {
					valid = true;
				}
				return valid;
			},
			// 验证是否为空
			validIsEmpty(str, tip) {
				if (str === '') {
					this.$api.msg(`${tip}不能为空`);
					return false;
				}
				return true;
			},
			// 验证码是否正确
			async validIsTrue(code) {
				let data = {
					account_user: this.phone,
					verifyCode: this.code
				}
				let res = await _isok(data)
				console.log(res)
				if (res.flag == false) {
					this.$api.msg(res.message);
					this.judgecode = false
				} else {
					this.judgecode = true
				}
			},
			async register() {
				if (this.validPhone(this.phone) && this.validIsEmpty(this.code, "验证码")) {
					this.validIsTrue(this.code)
					if (this.judgecode) {
						uni.navigateTo({
							url: '/pages/xiugai2/xiugai2?phone=' + this.phone
						});
						let data = {
							account_user: this.phone,
							verifyCode: this.code,
						}
						//let res = await _registerNewUser(data);
						if (data.flag == true) {
							setTimeout(() => {
								uni.hideLoading();
							}, 500)
						} else {
							setTimeout(() => {
								uni.hideLoading();
								this.$api.msg(data.message);
							}, 500)
						}
					}

				}
			},
			timewait(t) {
				const _this = this;
				setTimeout(() => {
					if (t >= 0) {
						// _this.codeMsg = t + '秒后点击';
						_this.codeMsg = t + 's';
						t--;
						_this.timewait(t);
					} else {
						_this.codeMsg = '获取验证码';
						t = 60;
						_this.btndisabled = false;
					}
				}, 1000)
			},
			async sendCode() {
				//验证手机号码是否合法
				if (!(/^1[13456789]\d{9}$/.test(this.phone))) {
					uni.showToast({
						title: '手机号码不规范',
						icon: 'none'
					});
					return;
				}

				let data = {
					account_user: this.phone,
				}
				let res = await _paschangecode(data)
				this.$api.msg(res.message)
				console.log(res)
				this.timewait(60)
				this.btndisabled = true;
			},

			showArctile() {
				uni.navigateTo({
					url: '/pages/agreement/agreement'
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.page {
		background-color: #ffffff;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100%;

		.group {
			padding: 114.58rpx 45.83rpx 379.17rpx;
			overflow-y: auto;

			.section {
				padding: 33.33rpx 25rpx;
				background-color: #a6a6a640;
				border-radius: 25rpx;

				.group_2 {
					width: 129.17rpx;

					.image_5 {
						margin-left: 79.17rpx;
						width: 50rpx;
						height: 50rpx;
					}

					.text_5 {
						margin-left: -129.17rpx;
						color: #808080;
						line-height: 36.46rpx;
					}
				}
			}

			.space-x-8 {

				&>view:not(:first-child),
				&>text:not(:first-child),
				&>image:not(:first-child) {
					margin-left: 16.67rpx;
				}
			}

			.group_3 {
				margin-top: 68.75rpx;
				padding: 37.5rpx 0;
				background-color: #a6a6a640;
				border-radius: 25rpx;

				.text_7 {
					margin-right: 16.67rpx;
					margin-top: 5rpx;
					color: #138f87;
				}

				//    .text-wrapper {
				//      padding: 37.5rpx 0;
				//      background-color: #a6a6a640;
				//      border-radius: 25rpx;
				//      .text_6 {
				// // margin-left: -129.17rpx;
				//        margin-left: 300.83rpx;
				//      }
				//    }
				.pos {
					position: absolute;
					left: 0;
					right: 0;
					top: 0;
					bottom: 0;
				}
			}

			.font_3 {
				// font-size: 41.67rpx;
				font-size: 36rpx;
				font-family: WenQuanYiMicroHeiMono;
				line-height: 37.5rpx;
				color: #a6a6a6;
				margin-left: 25rpx;
			}

			.group_4 {
				margin-top: 60.42rpx;
				padding: 0 20.83rpx;

				.section_2 {
					background-color: #cccccc;
					border-radius: 50%;
					width: 31.25rpx;
					height: 31.25rpx;

					&.checked {
						background-color: red;

						&::before {
							content: '';
							display: block;
							width: 16upx;
							height: 7upx;
							border-left: 3upx solid #fff;
							border-bottom: 3upx solid #fff;
							transform: translate(6upx, 10upx) rotate(-45deg);
						}
					}
				}

				.text_8 {
					color: #000000;
					font-size: 20.83rpx;
					font-family: WenQuanYiMicroHeiMono;
					line-height: 19.79rpx;
				}

				.text_9 {
					color: #0B97C4;
					font-size: 20.83rpx;
					font-family: WenQuanYiMicroHeiMono;
					line-height: 19.79rpx;
				}
			}

			// .button {
			//   margin-top: 68.75rpx;
			//   padding: 25rpx 0;
			//   background-color: #138f87;
			//   border-radius: 56.25rpx;
			//   .text_9 {
			//     color: #ffffff;
			//   }
			// }
			.uni-btn-v {
				button {
					background-color: #138f87;
					color: #ffffff;
					font-size: 50rpx;
					margin-top: 68.75rpx;
					padding: 25rpx 0;
					border-radius: 56.25rpx;
				}
			}

			.font_2 {
				// font-size: 50rpx;
				font-size: 45rpx;
				font-family: WenQuanYiMicroHeiMono;
				line-height: 45.83rpx;
			}

			.text_10 {
				margin-top: 75rpx;
				color: #a6a6a6;
				font-size: 33.33rpx;
				font-family: WenQuanYiMicroHeiMono;
				line-height: 30.21rpx;
			}
		}
	}
</style>
